package com.derbysoft.ota.application.translator.rs;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.ota.interfaces.protocol._2009a.AddressInfoType;
import com.derbysoft.ota.interfaces.protocol._2009a.AddressType;
import com.derbysoft.ota.interfaces.protocol._2009a.CountryNameType;
import com.derbysoft.ota.interfaces.protocol._2009a.StateProvType;
import com.derbysoft.remote.dswitch.generic.dto.AddressDTO;

public class AddressRSTranslator implements Translator<AddressDTO, AddressInfoType> {
	
    @Override
    public AddressInfoType translate(AddressDTO source) {
        AddressInfoType addressInfoType = new AddressInfoType();

        //country
        CountryNameType countryNameType = new CountryNameType();
        countryNameType.setCode(source.getCountry().getA2Code());
        countryNameType.setValue(source.getCountry().getName());
        addressInfoType.setCountryName(countryNameType);
        //state/province
        StateProvType stateProvType = new StateProvType();
        stateProvType.setValue(source.getStateName());
        addressInfoType.setStateProv(stateProvType);
        //city
        addressInfoType.setCityName(source.getCityName());
        //postal code
        addressInfoType.setPostalCode(source.getPostalCode());
        //street number
        AddressType.StreetNmbr streetNmbr = new AddressType.StreetNmbr();
        streetNmbr.setValue(source.getStreetNumber());
        addressInfoType.setStreetNmbr(streetNmbr);
        //address line
        addressInfoType.getAddressLine().add(source.getAddressLine());

        return addressInfoType;
    }
}
